package com.study.hot.flutter

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.study.hot.databinding.ActivityJumpFlutterpageBinding
import io.flutter.embedding.android.FlutterActivity
import org.jetbrains.anko.sdk27.coroutines.onClick

/**
 * <pre>
 *     author : slx
 *     time   : 2021/04/01
 *     desc   : 现有Android项目使用Flutter,跳转到flutter页面
 * </pre>
 */
/**
 * 嵌入到现有Android项目：
 * 1.编译为AAR文件（Android Archive）
 * 2.通过Flutter编译为aar，添加相关的依赖
 * 3.依赖模块的源码方式，在gradle进行配置
 */
class JumpFlutterPageActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityJumpFlutterpageBinding.inflate(layoutInflater)
        binding.run {
            setContentView(root)
            btnStart.onClick {
                // 启动Flutter页面
                startActivity(
                        FlutterActivity.createDefaultIntent(this@JumpFlutterPageActivity)
                )
            }

            btnStartWithRoute.onClick {
                startActivity(
                        FlutterActivity
                                .withNewEngine()
                                .initialRoute("/second")
                                .build(this@JumpFlutterPageActivity))
            }

        }
    }
}